﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
//using javax.management.relation;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;
using Project.AdminWeb.Models;
using Project.Application;
using Entity = Project.Domain.Entity;
namespace Project.AdminWeb.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly IRoleAppService _role;
        public HomeController(ILogger<HomeController> logger, IRoleAppService role)
        {
            _logger = logger;
            _role = role;
        }

        public IActionResult Index()
        {
            //var role = new Entity.Role()
            //{
            //    CreatorUserId = Guid.NewGuid().ToString(),
            //    TenantId = 10,
            //    Name = "LoginName",
            //    Description = "Description-裘千仞",
            //    ManageRole = "Role1,Role2,Role3"

            //};
            //  var c = _role.AddAsync(role);
            FilterDefinition<Entity.Role> filter = Builders<Entity.Role>.Filter.Where(c => c.Name != "");

            ViewBag.Role = _role.GetByFilterAsync(filter).Result.ToList();

            var AllItems = new List<string>();
            //var s = from item in AllItems
            //        where !item.IsDone
            //        orderby item.DueDate
            //        select (item.ID, item.Title);
            //Tuple<int, string> s = _un

            string[] fruits = { "apple", "banana", "mango", "orange",
                      "passionfruit", "grape" };

            var query = fruits.Select((fruit, index) =>
            new
            {
                index,
                str = fruit.Substring(0, index)
            });
            // Tuple<int, string> c = query.ToLookup<int, string>(c=>c.index); ;
            foreach (var obj in query)
            {
                Console.WriteLine("{0}", obj);
            }
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
